home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / Powervisor v1.10b disk2.adf / ExtractIndex.rexx < prev    next >
OS/2 REXX Batch file  |  1991-09-10  |  2KB  |  131 lines

  1. /* This ARexx script extracts an index file made by 'MakeIndex' */
  2.  
  3. parse arg fn
  4.  
  5. idxfnin='t:'||fn||'.tmp'
  6. confnin='t:'||fn||'.tmpc'
  7. idxfnout=fn||'.idx'
  8. confnout=fn||'.contents'
  9.  
  10. rc=open(o,"console:",'w')
  11.  
  12. rc=open(idxin,idxfnin,'r')
  13. if rc=0 then do
  14.    say
  15.    say 'Error opening file' idxfnin '!'
  16.    exit
  17. end
  18.  
  19. rc=open(conin,confnin,'r')
  20. if rc=0 then do
  21.    say
  22.    say 'Error opening file' confnin'!'
  23.    rc=close(idxin)
  24.    exit
  25. end
  26.  
  27. rc=open(idxout,idxfnout,'w')
  28. if rc=0 then do
  29.    say
  30.    say 'Error opening file for writing' idxfnout '!'
  31.    rc=close(idxin)
  32.    rc=close(conin)
  33.    exit
  34. end
  35.  
  36. rc=open(conout,confnout,'w')
  37. if rc=0 then do
  38.    say
  39.    say 'Error opening file for writing' confnout '!'
  40.    rc=close(idxout)
  41.    rc=close(idxin)
  42.    rc=close(conin)
  43.    exit
  44. end
  45.  
  46. /*------------*/
  47. /* Make index */
  48. /*------------*/
  49.  
  50. index=0
  51.  
  52. writech(o,'  [index:')
  53. writeln(idxout,'   Index for' fn)
  54.  
  55. do while eof(idxin)=0
  56.    lin=readln(idxin)
  57.    parse var lin linenr ':' after
  58.  
  59.    call writeindexes('¹ 1')
  60.    call writeindexes('² 2')
  61.    call writeindexes('³ 3')
  62. end
  63.  
  64. writech(o,index||']')
  65.  
  66. /*---------------*/
  67. /* Make contents */
  68. /*---------------*/
  69.  
  70. contents=0
  71.  
  72. writech(o,'  [contents:')
  73. writeln(conout,'   Contents for' fn)
  74.  
  75. do while eof(conin)=0
  76.    lin=readln(conin)
  77.  
  78.    parse var lin linenr ':' after
  79.  
  80.    after=strip(after,'B','=')
  81.    after=strip(after,'B',' ')
  82.  
  83.    olin=left(after||' ',40,'-') fn ':' linenr
  84.    writeln(conout,olin)
  85.    contents=contents+1
  86. end
  87.  
  88. say contents||']'
  89.  
  90. /*------------------*/
  91. /* Close everything */
  92. /*------------------*/
  93.  
  94. rc=close(idxin)
  95. rc=close(conin)
  96. address command 'delete quiet' idxfnin
  97. address command 'delete quiet' confnin
  98. rc=close(idxout)
  99. rc=close(conout)
  100. rc=close(o)
  101. exit
  102.  
  103. /*--------------------------------------------------------*/
  104. /* Subroutine to write all indexes for one line to a file */
  105. /*--------------------------------------------------------*/
  106.  
  107. writeindexes: procedure expose index idxout fn after linenr
  108.    parse arg isym inum
  109.  
  110.    inum=strip(inum,'B',' ')
  111.  
  112.    parse var after before (isym) rest
  113.  
  114.    rlinenr=linenr
  115.    do while rest~=''
  116.       if substr(rest,1,1)=isym then do
  117.          rest=substr(rest,2)
  118.          rlinenr=rlinenr||'!'
  119.       end
  120.       word=strip(subword(rest,1,inum),'T','.')
  121.       word=strip(word,'T',',')
  122.       word=strip(word,'T',')')
  123.       olin=left(word||' ',40,'-') left(fn,22) ':' rlinenr
  124.       writeln(idxout,olin)
  125.       index=index+1
  126.       parse var rest before (isym) rest
  127.       rlinenr=linenr
  128.    end
  129.  
  130.    return
  131.